Skip to content

Adding description of how to test a command which expects user input #2398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2013
Merged

Adding description of how to test a command which expects user input #2398

merged 3 commits into from
Apr 26, 2013

Conversation

Sgoettschkes
Copy link
Contributor

This PR adds a description on testing a command which uses the DialogHelper and expects some user input.

Q A
Doc fix? no
New docs? yes
Applies to 2.0+
Fixed tickets #2351

One thing I'm not sure about is if I should add a link to the section about command testing. If so, where should I add it?

{

// ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 3 dots

}

protected function getInputStream($input)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserting is not something that's usually done in a Command test. Mock objects are a better practise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from the description on how to test commands. I think as a comment it is ok because it ilustrates that the command is now being executed and one can either test the outcome or end the test.

@tiraeth
Copy link

tiraeth commented Apr 7, 2013

Impressive. I tried mocking DialogHelper using Mockery, with no luck, but this seems to be cleaner and easier. Unfortunately, this won't work if the order of questions for which we want user to provide answers to is non-deterministic. Is there any chance of getting a description about how to use Mockery in order to create more sophisticated tests for our commands?

@Sgoettschkes
Copy link
Contributor Author

I see your problem. Actually, testing the command itself with Mockery doesn't make much sense, much in the same way testing a controller in a unit test doesn't make much sense. Both are more or less boilerplate code, connecting your services to some front end (http or cli).

You could see if you can read the output stream and parse it, so you know which question is asked. Then you could provide some sort of mapping (if question x, answer with y). This of course means that rewriting one of your questions would break tests, but I guess it should be possible.

Anyway, I think this should be either discussed on the mailing list or postet to SO as to not pollute the PR.

weaverryan added a commit that referenced this pull request Apr 26, 2013
Adding description of how to test a command which expects user input
@weaverryan weaverryan merged commit 61b0787 into symfony:2.0 Apr 26, 2013
weaverryan added a commit that referenced this pull request Apr 26, 2013
@weaverryan
Copy link
Member

Thanks Sebastian - awesome work!

@Sgoettschkes Sgoettschkes deleted the issue2351 branch April 27, 2013 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants